<template>
  <div>
    <p><el-link icon="el-icon-edit" max-height="100%">编辑</el-link></p>
    <div>
      <el-form :inline="true" class="userDo-search">
        <el-form-item label="搜索：">
          <el-input v-model="aaa" size="small" placeholder="输入方案编码" />
        </el-form-item>
        <el-form-item>
          <el-input v-model="bbb" size="small" placeholder="输入方案名" />
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" @click="search()">查询</el-button>
          <el-button size="small" type="primary" @click="handleEdit1()">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :data="tableData"
      style="width: 100%"
      max-height="500"
    >
      <el-table-column
        fixed
        prop="id"
        label="编号"
        width="200"
      />
      <el-table-column
        prop="sender"
        label="发送人"
        width="200"
      />
      <el-table-column
        prop="types"
        label="个人通知(g)/部门通知(b)"
        width="200"
      />
      <el-table-column
        prop="create_time"
        label="发送日期"
        width="200"
      />
      <el-table-column
        prop="title"
        label="标题"
        width="200"
      />
      <el-table-column
        label="内容"
        width="200"
        prop="content"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        fixed="right"
        label="操作"
        width="200"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click.native.prevent="deleteRow(scope.$index, tableData)"
          >
            移除已读
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-button icon="el-icon-edit" type="text" @click="dialogVisibles = true">点击打开</el-button>

    <el-dialog
      title="提示"
      :visible.sync="dialogVisibles"
      width="100%"
      :before-close="handleClose"
    >
      <el-form :model="form">
        <el-form-item label="标题" :label-width="formLabelWidth">
          <el-input v-model="form.information.title" autocomplete="off" />
        </el-form-item>
        <el-form-item label="内容" :label-width="formLabelWidth">
          <el-input v-model="form.information.content" autocomplete="off" />
        </el-form-item>
        <el-form-item label="活动区域" :label-width="formLabelWidth">
          <el-transfer
            v-model="form.id"
            filterable
            :filter-method="filterMethod"
            filter-placeholder="请输入城市拼音"
            :data="data"
          />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibles = true">取 消</el-button>
        <el-button type="primary" @click="dialogVisible()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>

import { add, getList } from '@/api/table'

export default {
  data() {
    const generateData = _ => {
      const data = []
      const cities = ['上海', '北京', '广州', '深圳', '南京', '西安', '成都']
      const pinyin = ['shanghai', 'beijing', 'guangzhou', 'shenzhen', 'nanjing', 'xian', 'chengdu']
      cities.forEach((city, index) => {
        data.push({
          label: city,
          key: index,
          pinyin: pinyin[index]
        })
      })
      return data
    }
    return {
      data: generateData(),
      value: [],
      filterMethod(query, item) {
        return item.pinyin.indexOf(query) > -1
      },
      formLabelWidth: '120px',
      dialogVisibles: false,
      aaa: '',
      bbb: '',
      search() {},
      // 重置事件
      handleEdit1() {
        this.$router.go(0)
      },
      drawer: false,
      tableData: [],
      dialogTableVisible: false,
      dialogVisible() {
        console.log(this.form)
        add(this.form).then(res => {
          console.log(res.data)
          this.tableData = res.data
        })
      },
      content: '',
      form: {
        information: {
          title: '',
          content: '',
          status: '',
          types: ''
        },
        id: '',
        creator_id: ''
      }
    }
  },
  mounted() {
  },
  created() {
    getList(2).then(res => {
      console.log(res.data)
      this.tableData = res.data
    })
  },
  methods: {
    deleteRow(index, rows) {
      console.log(rows[index].id)
      // rows.splice(index, 1)
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {})
    }
  }
}
</script>
